package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.custom.converter.StringToBaseEnumConverterFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author:高尚
 * @data:2025/7/11 0:30
 * @description:  实现该接口可自定义Spring MVC配置
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Autowired //注入一个自定义的枚举类型转换器工厂
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;
    @Override //重写该方法，将自定义的枚举转换器注册到Spring中,用于将字符串自动转换为枚举类型
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(stringToBaseEnumConverterFactory);
    }
}
